package com.example.taigame;

import java.util.List;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.example.adapter.DanhMuc_ListView_Adapter;

public class ListViewDanhMuc extends Fragment {

	private static final String ARG_POSITION = "position";

	private int position;

	public static ListViewDanhMuc newInstance(int position) {
		ListViewDanhMuc f = new ListViewDanhMuc();
		Bundle b = new Bundle();
		b.putInt(ARG_POSITION, position);
		f.setArguments(b);
		return f;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		position = getArguments().getInt(ARG_POSITION);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.listview_installed_packed, container, false);
		ListView g = (ListView) view.findViewById(R.id.listView1);
		g.setAdapter(new DanhMuc_ListView_Adapter(getActivity()));
		g.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(MyApp._currentActivity, GroupGameActivity.class);
				intent.putExtra("gameType", arg2);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				MyApp._currentActivity.startActivity(intent);
			}
		});
		return view;
	}
	
	private List<ApplicationInfo> getListApp(){
		final PackageManager pm = getActivity().getPackageManager();
		//get a list of installed apps.
		List<ApplicationInfo> packages = pm.getInstalledApplications(0);
		return packages;
	}
}